package com.jiayou.tool

import com.jiayou.message.OnLineMessage
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.time.LocalDateTime

/**
@author 李 双
@data   2020-11-19  16:32
@info
 */
class SerializableTool {
    companion object {
        fun ObjectToByteArray(obj: Any?): ByteArray {
            val byteArrayOutputStream = ByteArrayOutputStream()
            val objectOutputStream = ObjectOutputStream(byteArrayOutputStream)
            objectOutputStream.writeObject(obj)
            objectOutputStream.flush()
            return byteArrayOutputStream.toByteArray()
        }

        fun ByteArrayToObject(byteArray: ByteArray?): Any {
            val `in` = ByteArrayInputStream(byteArray)
            val sIn = ObjectInputStream(`in`)
            return sIn.readObject()
        }
    }
}